# -*- coding:utf-8 -*-
# @Time: 2020/8/27 17:30
# @Author: liupengfei
# @File: filters.py

import django_filters
from django.contrib.auth import get_user_model
from apps.member.models import Member

User = get_user_model()


class AccountFilter(django_filters.FilterSet):
    username = django_filters.CharFilter(field_name='username', lookup_expr='icontains')

    class Meta:
        model = User
        fields = ['username', 'is_active']


class MemberFilter(django_filters.FilterSet):
    username = django_filters.CharFilter(field_name='user__username', lookup_expr='icontains')
    nickname = django_filters.CharFilter(field_name='user__nickname', lookup_expr='icontains')
    gender = django_filters.ChoiceFilter(field_name='gender', choices=Member.GENDER_CHOICES)
    is_active = django_filters.CharFilter(field_name='user__is_active')

    class Meta:
        model = Member
        fields = ['username', 'nickname', 'gender', 'is_active']
